// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from "vue";
import App from "./App";
import router from "./router";
import service from "./public/server.js";
import 'muse-ui/lib/styles/base.less';
import {
  Form,
  List,
  Menu,
  Grid,
  TextField,
  Snackbar,
  Icon,
  Button
} from "muse-ui";
import 'muse-ui/lib/styles/theme.less';
// import "muse-ui/dist/muse-ui.css";
import "muse-ui-message/dist/muse-ui-message.css";
import "iview/dist/styles/iview.css";
// import './public/element-ui.css';
import "./public/material-icons.css";
import "./public/font_750491_7yfljhmk7kr.css";
// import 'font-awesome/css/font-awesome.min.css';
import "font-awesome/css/font-awesome.css";

import myMqtt from "@/public/mqtt.js";

import Bus from "@/public/eventBus";
import { ToastConfig } from "./public/setting.js";
import Toast from "muse-ui-toast";
import theme from "muse-ui/lib/theme";
import Message from "muse-ui-message";
import ElementUI from "element-ui";
// import 'element-ui/lib/theme-chalk/index.css';
import "../src/assets/css/element-variables.scss";
import "../src/assets/css/common.scss";
import VueClipboard from "vue-clipboard2";
Vue.use(VueClipboard);
import VCharts from "v-charts";
import flag from './public/flag'
Vue.use(VCharts);
// import Table from 'iview';
// router.beforeEach((to, from, next) => {console.log(to, from, next);})
// import 'muse-ui-loading/dist/muse-ui-loading.css';
// import Loading from 'muse-ui-loading';

theme.add(
  "carbon",
  {
    primary: "#2261ca",
    secondary: "#ff4081",
    success: "#4caf50",
    error: "#cc2432",
    warning: "#ffeb3b",
    white: "#ffffff"
  },
  "light"
);
// Toast.config(ToastConfig);
Vue.use(Toast);
theme.use("carbon");

Vue.use(Form);
Vue.use(List);
Vue.use(Menu);
Vue.use(Grid);
Vue.use(TextField);
Vue.use(Icon);
Vue.use(Button);
Vue.use(Snackbar);
Vue.use(Message);

Vue.use(ElementUI);

Vue.config.productionTip = false;
Vue.prototype.$http = service;
Vue.prototype.$flag = flag
// let reciveMessage = {};
// let reciveInstMess = {};
new myMqtt(`/nc/gateway/web/reply`, data => {
  Bus.$emit("reciveEvent", data);
  if(JSON.parse(data).type !== 'testEnd') {
    Vue.prototype.$flag.setFlag(true)
    Vue.prototype.$reciveEvent = data
  }
});
new myMqtt(`/nc/gateway/web/instruments`, data => {
  Bus.$emit("reciveInstrEvent", data);
});

// Vue.prototype.imgBaseUrl = "http://39.105.56.24:7001/public/upload/";
// Vue.prototype.uploadUrl = "http://39.105.56.24:7001/v1/upload";
// Vue.prototype.imgBaseUrl = "http://192.168.1.126:7001/public/upload/";
// Vue.prototype.uploadUrl = "http://192.168.1.126:7001/v1/upload";
Vue.prototype.imgBaseUrl = "http://127.0.0.1:7001/public/upload/";
Vue.prototype.uploadUrl = "http://127.0.0.1:7001/v1/upload";
/* eslint-disable no-new */
//  前置路由守卫 当用户没有登录时 跳转至登录页
router.beforeEach((to, from, next) => {
  if (to.path === '/') return next()
    const userinfo = window.sessionStorage.getItem('userInfo')
    if(userinfo === null) {
      // next(false)
      return next({path: '/'})
  }
  next()
})
new Vue({
  el: "#app",
  router,
  components: {
    App
  },
  template: "<App/>"
});
